package com.kk.score.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kk.score.dao.GradeDao;
import com.kk.score.dao.TaskDao;
import com.kk.score.entity.GradeEntity;
import com.kk.score.entity.TaskEntity;
import com.kk.score.entity.vo.*;
import com.kk.score.service.GradeService;
import com.kk.score.service.TaskService;
import com.kk.score.utils.DateUtils;
import com.kk.score.utils.PageUtils;
import com.kk.score.utils.Query;
import com.kk.score.utils.SpringSecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;


@Service("gradeService")
public class GradeServiceImpl extends ServiceImpl<GradeDao, GradeEntity> implements GradeService {

    @Autowired
    private GradeDao gradeDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        String status = (String) params.get("status");
//        if (!StringUtils.hasText(status)) {
//            status = "0";
//        }
        String userUid = SpringSecurityUtils.getUid();
        return new PageUtils(gradeDao.findGradeAllByUser(new Query<GradeVo>().getPage(params), userUid, null));
    }

    @Override
    public PageUtils queryPersonList(Map<String, Object> params) {
        return new PageUtils(gradeDao.findGradePersonByPushUid(new Query<GradePersonVo>().getPage(params), (String) params.get("pushUid")));
    }

    @Override
    public PageUtils queryPageUnitList(Map<String, Object> params) {
        String status = (String) params.get("status");
        String year = (String) params.get("year");
        if (!StringUtils.hasText(year)) {
            year = DateUtils.getYears();
        }
        if (!StringUtils.hasText(status)) {
            status = "1";
        }
        IPage<?> pushPage = gradeDao.findPushPage(new Query<UnitVo>().getPage(params), status, year);
        @SuppressWarnings("unchecked")
        List<UnitVo> records = (List<UnitVo>) pushPage.getRecords();

        return new PageUtils(pushPage);
    }

}